package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YtBillMaterialSupplier;
import com.ruoyi.system.service.IYtBillMaterialSupplierService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料商发票Controller
 * 
 * @author magichaohao
 * @date 2021-05-19
 */
@Controller
@RequestMapping("/system/supplier")
public class YtBillMaterialSupplierController extends BaseController
{
    private String prefix = "system/supplier";

    @Autowired
    private IYtBillMaterialSupplierService ytBillMaterialSupplierService;

    @RequiresPermissions("system:supplier:view")
    @GetMapping()
    public String supplier()
    {
        return prefix + "/supplier";
    }

    /**
     * 查询材料商发票列表
     */
    @RequiresPermissions("system:supplier:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YtBillMaterialSupplier ytBillMaterialSupplier)
    {
        startPage();
        List<YtBillMaterialSupplier> list = ytBillMaterialSupplierService.selectYtBillMaterialSupplierList(ytBillMaterialSupplier);
        return getDataTable(list);
    }

    /**
     * 导出材料商发票列表
     */
    @RequiresPermissions("system:supplier:export")
    @Log(title = "材料商发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YtBillMaterialSupplier ytBillMaterialSupplier)
    {
        List<YtBillMaterialSupplier> list = ytBillMaterialSupplierService.selectYtBillMaterialSupplierList(ytBillMaterialSupplier);
        ExcelUtil<YtBillMaterialSupplier> util = new ExcelUtil<YtBillMaterialSupplier>(YtBillMaterialSupplier.class);
        return util.exportExcel(list, "材料商发票数据");
    }

    /**
     * 新增材料商发票
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存材料商发票
     */
    @RequiresPermissions("system:supplier:add")
    @Log(title = "材料商发票", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YtBillMaterialSupplier ytBillMaterialSupplier)
    {
        return toAjax(ytBillMaterialSupplierService.insertYtBillMaterialSupplier(ytBillMaterialSupplier));
    }

    /**
     * 修改材料商发票
     */
    @GetMapping("/edit/{materialSupplierInvoiceId}")
    public String edit(@PathVariable("materialSupplierInvoiceId") Long materialSupplierInvoiceId, ModelMap mmap)
    {
        YtBillMaterialSupplier ytBillMaterialSupplier = ytBillMaterialSupplierService.selectYtBillMaterialSupplierById(materialSupplierInvoiceId);
        mmap.put("ytBillMaterialSupplier", ytBillMaterialSupplier);
        return prefix + "/edit";
    }

    /**
     * 修改保存材料商发票
     */
    @RequiresPermissions("system:supplier:edit")
    @Log(title = "材料商发票", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YtBillMaterialSupplier ytBillMaterialSupplier)
    {
        return toAjax(ytBillMaterialSupplierService.updateYtBillMaterialSupplier(ytBillMaterialSupplier));
    }

    /**
     * 删除材料商发票
     */
    @RequiresPermissions("system:supplier:remove")
    @Log(title = "材料商发票", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ytBillMaterialSupplierService.deleteYtBillMaterialSupplierByIds(ids));
    }
}
